package com.example.administrator.jingpingou.activity;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.ListView;

import com.activeandroid.Model;
import com.activeandroid.query.Select;
import com.example.administrator.jingpingou.R;
import com.example.administrator.jingpingou.adapter.MineCollectAdapter;
import com.example.administrator.jingpingou.application.MyApplication;
import com.example.administrator.jingpingou.bean.MineCollectBean;

import java.util.ArrayList;
import java.util.List;

public class MineCollectActivity extends AppCompatActivity {

    private ListView mListView;
    private List<MineCollectBean> mData;
    private String num_iid;
    private MineCollectAdapter mAdapter;
    private ImageView mImageBack;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mine_collect);
        Select select = new Select();
//         modelsData = select.from(MineCollectBean.class).where("num_iid=?").execute();
        mData = select.from(MineCollectBean.class).where("userName=?", MyApplication.getUserName()).execute();

        initView();
        setData();
        setListener();
    }

    private void setListener() {
        mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Intent intent = new Intent(MineCollectActivity.this,WebTaoActivity.class);
                intent.putExtra("num_iid",num_iid);
                startActivity(intent);
            }
        });
        mImageBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initView() {
        mImageBack = (ImageView) findViewById(R.id.iv_activity_collect_back);
        mListView = (ListView) findViewById(R.id.lv_activity_collect);
    }

    private void setData() {
        mAdapter =new MineCollectAdapter(mData,MineCollectActivity.this);
        mListView.setAdapter(mAdapter);
    }
}
